package com.leetcode.LeetCode精选TOP面试题;

/**
 * @author 覃国强
 * @date 2022-07-05 17:40
 */
public class 题库_0189_轮转数组 {

  static
  class Solution {
    public void rotate(int[] nums, int k) {
      if (nums == null || nums.length == 0 || k == 0) {
        return;
      }

      int count = 0;
      for (int start = 0; count < nums.length; ++start) {
        int prev = nums[start];
        int index = start;
        do {
          index = (index + k) % nums.length;
          int temp = nums[index];
          nums[index] = prev;
          prev = temp;
          ++count;
        } while (index != start);
      }
    }
  }

}
